<template>
  <div class="video" @click="toDetail(props.data?.videoId)">
    <div style="width: 100%; height: 100%; position: relative">
      <el-image :src="props.data?.firstImgUrl" class="video-img"></el-image>
      <div class="data-icon">
        <div class="icon-item">
          <img src="@/assets/icon/chakan3.png" alt="" class="sicon" />
          <div>{{ tool.numberTo(props.data?.lookCount) }}</div>
        </div>
        <div class="icon-item">
          <img src="@/assets/icon/dianzan3.png" alt="" class="sicon" />
          <div>{{ tool.numberTo(props.data?.thumbUp) }}</div>
        </div>
        <div class="icon-item">
          <img src="@/assets/icon/shoucang3.png" alt="" class="sicon" />
          <div>{{ tool.numberTo(props.data?.collection) }}</div>
        </div>
      </div>
    </div>
    <div class="muti-ell-2 common-f-14 title">
      {{ props.data?.title }}
    </div>
    <div class="video-bottom">
      <div style="display: flex; align-items: center" class="bottom-item">
        <img
          src="@/assets/icon/uper.png"
          alt=""
          class="sicon"
          style="margin-right: 5px"
        />
        <div>
          {{ props.data?.user.nickname || "未知" }}
        </div>
      </div>
      <div class="bottom-item">
        <el-button type="text" :icon="Close" @click.stop="cancel(props.data?.id)">
          {{ props.type === 3 ? "取消收藏" : "取消点赞" }}
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from "vue";
import tool from "@/assets/js/tool";
import { Close } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";

const emits = defineEmits(["cancel"]);
const props = defineProps({
  data: {
    type: Object,
    default: () => {},
  },
  type: {
    type: Number,
    default: 3,
  },
  time: {
    type: String,
    default: "1996-10-10",
  },
});

const cancel = (id) => {
  if (id === undefined || id === null) {
    ElMessage.error("抱歉，当前视频不存在");
    return;
  }
  emits("cancel", id, props.type);
};

const router = useRouter();
const toDetail = (id) => {
  router.push({
    path: "/client/detail",
    query: {
      vid: id,
    },
  });
};
</script>

<style scoped lang="scss">
.video {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-bottom-right-radius: 5px;
  border-bottom-left-radius: 5px;
  box-shadow: 0 0 4px 2px #ebebeb;
}

.title {
  width: 100%;
  text-align: left;
  padding: 2px 0;
  margin-left: 10px;
  min-height: 35px;
}
.data-icon {
  position: absolute;
  display: flex;
  justify-content: space-between;
  bottom: 4px;
  width: 100%;
  box-sizing: border-box;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.3) 100%
  );
  .icon-item {
    display: flex;
    align-items: center;
    padding: 2px 5px;
    color: #fff;
    font-size: 12px;
  }
}
.video-img {
  width: 100%;
  height: 120px;
}

.video-bottom {
  display: flex;
  align-items: center;
  font-size: 14px;
  width: 94%;
  line-height: 30px;
  justify-content: space-between;
}
</style>
import { ElMessage } from "element-plus";
